import axios from 'axios';
import qs from 'query-string';
import {
  PageQueryResponseModel,
  BasePageQueryRequestModel,
} from '@/types/common';

export interface ProjectModel {
  id: number;
  projectName: string;
  orderIndex: number;
  enabled: boolean;
  createTime: number;
  updateTime: number;
}

export interface PageQueryProjectParams extends BasePageQueryRequestModel {
  enabled: boolean | undefined;
  orderIndex: number | undefined;
  createTime: number[] | undefined;
  updateTime: number[] | undefined;
}

export function getPageProject(params: PageQueryProjectParams) {
  return axios.get<PageQueryResponseModel<ProjectModel>>(
    '/api/project/page-project',
    {
      params,
      paramsSerializer: (obj) => {
        return qs.stringify(obj);
      },
    }
  );
}

export interface EditProjectModel {
  id: number; // 项目Id
  projectName: string; // 项目名称
  orderIndex: number; // 排序字段
}

export function insertProject(data: EditProjectModel) {
  return axios.post('/api/project/project', data);
}

export function updateProject(data: EditProjectModel) {
  return axios.put('/api/project/project', data);
}

// 启用或禁用项目
export function patchProject(projectId: number, enabled: boolean) {
  return axios.patch(`/api/project/project/${projectId}/${enabled}`);
}

// 删除项目
export function deleteProject(projectId: number) {
  return axios.delete(`/api/project/project/${projectId}`);
}
